package com.example.reference_book.util;

import com.example.reference_book.entity.DeptInfo;
import com.example.reference_book.filter.DeptFilter;
import com.example.reference_book.filter.deptImpl.DeptAroundFilter;
import com.example.reference_book.filter.deptImpl.DeptNameFilter;
import com.example.reference_book.filter.deptImpl.DeptSchoolFilter;

import java.util.List;

public class DeptSearchUtil {
    public static DeptSearchUtil searchUtil;
    public static List<DeptInfo> list;
    private DeptSearchUtil (){

    }

    public void init(List<DeptInfo> list) {
        this.list = list;
    }

    public static DeptSearchUtil getSearchUtil() {
        if (searchUtil == null) {
            synchronized (DeptSearchUtil.class) {
                if (searchUtil == null) {
                    searchUtil = new DeptSearchUtil();
                }
            }
        }
        return searchUtil;
    }

    public List<DeptInfo> searchByKey(int type, String key){
        DeptFilter filter;
        switch (type){
            case 1:{
                filter = new DeptSchoolFilter();
                break;
            }
            case 2:{
                filter = new DeptNameFilter();
                break;
            }
            default:
                filter = new DeptAroundFilter();
        }
        return filter.getList(key,list);
    }
}
